<!-- 统计卡片 -->
<template>
  <div>
    <div class="ele-page-header">
      <div class="selectTime flex-align-center">
        <!-- <div class="orderStatus">订单状态:</div> -->
        <ul class="timeTab"
            v-for="(item, index) in orderStatusArr"
            :key="index">
          <li :class="[currentIndex == index ? 'active' : '']"
              @click="switchTimeTab(index,item.value)">{{ item.value }}</li>
        </ul>
        <div :class="[
			  'ele-inline-block',
			  { 'hidden-sm-and-down': styleResponsive }
			]"
             style="width: 260px; margin-left: 10px">
          <el-date-picker unlink-panels
                          type="daterange"
                          class="ele-fluid"
                          @change="selsectTime"
                          :default-time="['00:00:00', '23:59:59']"
                          value-format="yyyy-MM-dd"
                          end-placeholder="结束日期"
                          start-placeholder="开始日期"
                          v-model="datetime"
                          range-separator="至"
                          size="small" />
        </div>
      </div>
    </div>

    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-card class="analysis-chart-card"
                 shadow="never">
          <template v-slot:header>
            <div class="ele-cell">
              <div class="ele-cell-content">套餐卡充值总笔数</div>

            </div>
          </template>
          <div class="analysis-chart-card-num ele-text-heading">¥ {{ headerPreviewObject?.package_count }}</div>

        </el-card>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-card class="analysis-chart-card"
                 shadow="never">
          <template v-slot:header>
            <div class="ele-cell">
              <div class="ele-cell-content">扫码充值总金额</div>

            </div>
          </template>
          <div class="analysis-chart-card-num ele-text-heading">¥ {{ headerPreviewObject?.shaoma_amount
 }}</div>

        </el-card>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-card class="analysis-chart-card"
                 shadow="never">
          <template v-slot:header>
            <div class="ele-cell">
              <div class="ele-cell-content">充值总金额</div>

            </div>
          </template>
          <div class="analysis-chart-card-num ele-text-heading">¥ {{ headerPreviewObject?.
total_amount
 }}</div>

        </el-card>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 5, md: 12 } : { span: 5 }">
        <el-card class="analysis-chart-card"
                 shadow="never">
          <template v-slot:header>
            <div class="ele-cell">
              <div class="ele-cell-content">线下充值总金额</div>

            </div>
          </template>
          <div class="analysis-chart-card-num ele-text-heading">¥ {{ headerPreviewObject?.xianxia_amount }}</div>

        </el-card>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 4, md: 12 } : { span: 4 }">
        <el-card class="analysis-chart-card"
                 shadow="never">
          <template v-slot:header>
            <div class="ele-cell">
              <div class="ele-cell-content">在线充值总金额</div>

            </div>
          </template>
          <div class="analysis-chart-card-num ele-text-heading">¥ {{ headerPreviewObject?.zaixian_amount }}</div>

        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
	
	<script>
import { use } from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { LineChart, BarChart } from 'echarts/charts';
import { GridComponent, TooltipComponent } from 'echarts/components';


import { echartsMixin } from '@/utils/echarts-mixin';
import { rechargeStatistics } from '@/api/financialManagement/index'
use([CanvasRenderer, LineChart, BarChart, GridComponent, TooltipComponent]);
import moment from 'moment';
export default {
  components: {},
  mixins: [echartsMixin(['visitChart', 'payNumChart'])],
  data () {
    return {
      currentIndex: 0,
      // 访问量折线图配置
      visitChartOption: {},
      // 支付笔数柱状图配置
      payNumChartOption: {},
      headerPreviewObject: null,
      sumbitForm: null,
      timeArr: [],
      form: {
        start_time: '',
        end_time: ''
      },
      datetime: [],
      currentMoment: '',
      orderStatusArr: [
        {
          value: '全部',
          id: 0
        },

        {
          value: '今日',
          id: 1
        },

        {
          value: '前七天',
          id: 2
        },

        {
          value: '最近一个月',
          id: 3
        },

      ]
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  created () {
    this.switchTimeTab(0, '全部');
  },
  methods: {
    selsectTime (timeArr) {
      console.log(timeArr);
      if (timeArr) {
        this.form.start_time = timeArr[0];
        this.form.end_time = timeArr[1];


        this.getPayNumData();
        this.currentIndex = 100
      } else {
        this.switchTimeTab(0, '全部');
      }
    },
    switchTimeTab (index, value) {
      this.currentIndex = index;
      if (value == '全部') {
        this.form.start_time = null;
        this.form.end_time = null;
        this.getPayNumData();
      } else if (value == '今日') {
        this.datetime = [];
        this.currentMoment = moment();
        this.currentMoment.startOf('day');

        const currentDate = this.currentMoment.format('YYYY-MM-DD');
        console.log(currentDate);

        (this.form.start_time = currentDate);
        this.form.end_time = currentDate;
        this.getPayNumData();
      } else if (value == '前七天') {
        this.datetime = [];
        this.currentMoment = moment();
        const currentDate = this.currentMoment.format('YYYY-MM-DD');
        console.log(currentDate);

        this.currentMoment.startOf('day');
        const previousDate = this.currentMoment.subtract(7, 'days');

        // 格式化为指定的字符串格式（YYYY-MM-DD HH:mm:ss）
        const formattedDate = previousDate.format('YYYY-MM-DD');
        console.log(formattedDate);
        this.form.start_time = formattedDate;
        this.form.end_time = currentDate;
        this.getPayNumData();
      } else {
        this.datetime = [];
        this.currentMoment = moment();
        const currentDate = this.currentMoment.format('YYYY-MM-DD');
        console.log(currentDate);

        this.currentMoment.startOf('day');
        const previousDate = this.currentMoment.subtract(1, 'months');

        // 格式化为指定的字符串格式（YYYY-MM-DD HH:mm:ss）
        const formattedDate = previousDate.format('YYYY-MM-DD');
        console.log(formattedDate);
        this.form.start_time = formattedDate;
        this.form.end_time = currentDate;
        this.getPayNumData();
      }

    },

    /* 获取数据 */
    async getPayNumData () {
      const res = await rechargeStatistics({
        start_time: this.form.start_time,
        end_time: this.form.end_time
      })
      console.log(res)
      if (res.code == 0) {
        this.headerPreviewObject = res.data
      }
    }
  }
};
</script>
	
<style lang="less" scoped>
.packageCardArr {
  position: relative;
  margin-top: 32px;
  padding: 25px 20px;
  height: 108px;
  border-radius: 20px;
  background-repeat: no-repeat;
  background-size: cover;

  background-image: (var(--bg-image));
  // background-image: url('../../../static/套餐卡背景/矩形 1591.png');

  .avatar {
    width: 34px;
    height: 34px;
  }

  .rechargeBtn {
    width: 61.25px;
    height: 26px;
    border-radius: 20px;
    z-index: 999;
    background: rgb(255, 255, 255);
  }

  .rechargeBtn-noListing {
    width: 110px;
    height: 52px;
    border-radius: 10px;
  }

  .centerText {
    width: 258px;
  }

  .price {
    color: #fff;
    font-size: 16px;
    font-weight: 700;
  }

  .priceText {
    color: rgb(255, 255, 255);
    font-size: 16px;
    font-weight: 400;
  }
}
.selectTime {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .timeTab {
    display: flex;
    align-items: center;
    margin-right: 20px;
    li {
      list-style-type: none;
      display: block;
      width: 110px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border: 1px solid #d9d9d9;
      border-radius: 10px;
    }
    .active {
      width: 110px;
      height: 38px;
      border-radius: 6px;
      background: #1890ff;
      color: #fff;
      text-align: center;
      line-height: 38px;
    }
  }
  .orderStatus {
    min-width: 77px;
    height: 34px;
    font-size: 14px;
    line-height: 34px;
  }
  .filterDate {
    text-align: center;
    line-height: 34px;
    width: 90px;
    height: 34px;
    font-size: 14px;
    border-radius: 2px 0px 0px 2px;
    border: 1px solid #d9d9d9;
    border-right: none;
  }
  .ele-fluid {
    width: 300px !important;
  }
}
.analysis-chart-card-num {
  font-size: 30px;
}

.analysis-chart-card-content {
  height: 40px;
  box-sizing: border-box;
  margin-bottom: 12px;
}

.analysis-chart-card-text {
  padding-top: 12px;
}
</style>
	